#include "customerinfo.h"
#include "ui_customerinfo.h"
#include<QMessageBox>
#include "ClientSocket.h"
#include "SocketException.h"
#include "vector_serialization.h"
#include<iostream>
#include"login.h"

customerinfo::customerinfo(QWidget *parent, std::string name) :
        QWidget(parent),
        ui(new Ui::customerinfo)
{
        ui->setupUi(this);
        ui->label_workername->setText(QString::fromStdString("工作人员:"+name));
        connect(ui->pushButton_submit, SIGNAL(clicked()), this, SLOT(handleSubmit()));

}


customerinfo::~customerinfo()
{
        delete ui;
}

void customerinfo::handleSubmit() {
        std::string sendmsg, reply;
        std::string cname, cid, caddress, ctel, cstoretype, cidnum, cidtype, ctime;
        cname = ui->lineEdit_cname->text().toStdString();
        cid = ui->lineEdit_cid->text().toStdString();
        caddress = ui->lineEdit_caddress->text().toStdString();
        ctel = ui->lineEdit_ctel->text().toStdString();
        cstoretype = ui->comboBox_cstoretype->currentText().toStdString();
        cidnum = ui->lineEdit_cidnum->text().toStdString();
        cidtype = ui->comboBox_cidtype->currentText().toStdString();
        ctime = ui->comboBox_ctime->currentText().toStdString();
        map<std::string, std::string> smap;
        std::cout << "cstoretype:" << cstoretype << std::endl;
        smap["code"] = "001";
        smap["cname"] = cname;
        smap["cid"] = cid;
        smap["caddress"] = caddress;
        smap["ctel"] = ctel;
        smap["cmoney"] = "10";
        smap["cstoretype"] = cstoretype;
        smap["cidnum"] = cidnum;
        smap["cidtype"] = cidtype;
        smap["ctime"] = ctime;
        sendmsg = save(smap);
        ClientSocket client_socket("localhost",30000);
        client_socket << sendmsg;
        client_socket >> reply;
        QString re = QString::fromStdString(reply);
        QMessageBox::about(0,"reply",re);
}
